<template>
  <div>
    <h1>登录</h1>
    <table class="table table-bordered">
      <tr>
        <td>账号</td>
        <td><input type="text" v-model="state.userName" /></td>
      </tr>
      <tr>
        <td>密码</td>
        <td><input type="password" v-model="state.userPwd" /></td>
      </tr>
      <tr>
        <td></td>
        <td><input type="button" value="登录" @click="deng" /></td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';
import { useStore } from '../store/use';
const store = useStore();
const router = useRouter();
const route = useRoute();

let data = reactive({
  state: {
    userName: '',
    userPwd: ''
  }
});

let { state } = toRefs(data);

const deng = () => {
  axios({
    url: '/api/Users/GetUserInfo',
    method: 'get',
    params: state.value
  }).then((res) => {
    console.log(res);
    if (res.data.data.length == 0) {
      router.push("/zhuce")
      return;
     } else{
       store.userInfo=res.data.data[0]
       if(res.data.data[0].TypeName=="管理员"){
        alert('登录成功');
        router.push("/show")
       }
       else{
        alert('登录成功');
        router.push("/show")
       }
    }
  });
};
</script>

<style scoped></style>
